package com.leyou.auth.utils;

import com.leyou.auth.dto.UserDetail;

@SuppressWarnings("ALL")
/**
 * @Description :
 * @author     :LD
 */
public class UserContext {
    private static final ThreadLocal<UserDetail> tl = new ThreadLocal<>();

    /**
     * 存储一个用户到当前线程
     * @param user 用户信息
     */
    public static void setUser(UserDetail user){
        tl.set(user);
    }

    /**
     * 从当前线程获取一个用户
     * @return 用户信息
     */
    public static UserDetail getUser() {
        return tl.get();
    }

    /**
     * 从当前线程移除用户
     */
    public static void removeUser() {
        tl.remove();
    }
}

